/** 
 * @fileoverview 
 * layer package
 * 
 * 
 * @author Kelemen Viktor kelemen.viktor@gmail.com
 * @version 0.1
 * 
 */

YAHOO.namespace('layer');

	YAHOO.layer = function(id)	{
		
		
		// this.functions[name] = { function, counter }
		this.functions = {};
		//this.functioncounter = []
		
		
		this.layerdiv = document.createElement('div');
		this.layerdiv.setAttribute('id',id);
		$('screen').appendChild(this.layerdiv);
		
		this.changedflag = false;
		
		/**
		 * Gets a function
		 * @param {Object} name
		 */
		this.get = function(name)	{
			return this.functions[name];
		}
		
		/**
		 * Deletes a function
		 * @param {Object} name
		 */
		this.del = function(name)	{
			this.functions[name]=null;
		}
		
		this.addTo = function(name, el, counter)	{
			
			switch (typeof(el)) {
				case "function":
					if (counter==null) counter=-1;
					this.functions[name]={ f: el, counter: counter};
					this[name]=el;
					
					break;
				default:
					log(typeof(el));
			}
			
		}
		
		this.draw = function()	{
			
			var _self = this; 
			
			try {
			
			for (i in this.functions) {
				if (this.functions[i]!=null)
					if (this.functions[i].counter==-1) this.functions[i].f(); else
						if (this.functions[i].counter>0) { this.functions[i].f(); this.functions[i].counter--;}
			}
			
			} catch(e) { debug(e); }

		}
		
		
		
		
	}